package moon.search.criterion.logic;

import java.util.ArrayList;
import java.util.List;

import moon.search.criterion.Criterion;
import moon.search.criterion.IllegalCriterionException;
import moon.search.criterion.LogicalCriterion;

public class Or extends LogicalCriterion {
	

	public Or(Criterion ... list){
		this.setCriteria(new ArrayList<Criterion>());
		for (Criterion criterion : list){
			this.getCriteria().add(criterion);
		}
	}
	
	
	public boolean isFulfilled(Object type) throws IllegalCriterionException{
		
		List<Criterion> criteria = this.getCriteria();
		boolean result = false;
		
		for (Criterion c : criteria){
			result |= c.isFulfilled(type);
			
			// optimization, shot-circuit evaluation
			if (result){
				return true;
			}
		}		
		return result;
	}

}
